﻿using System;
using System.Collections.Generic;
using STeaL.Functional;

namespace STeaL.Algorithm {

  public static partial class IListExtensions {
#region random_shuffle
    public static void random_shuffle<T>(this IList<T> list, int first, int last, Random rnd) {
      int next = first;
      for ( int index = 2; ++next != last; ++index ) {
        iter_swap(list, next, first + rnd.Next(index));
      }
    }

    public static void random_shuffle<T>(this IList<T> list, int first, int last) {
      random_shuffle(list, first, last, new Random());
    }

    public static void random_shuffle<T>(this IList<T> list, Random rnd) {
      random_shuffle(list, 0, list.Count, rnd);
    }

    public static void random_shuffle<T>(this IList<T> list) {
      random_shuffle(list, 0, list.Count, new Random());
    }

#endregion
  }
}
